<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <button id="btn">点击</button>
        <div id="app"></div>
    </div>
</body>
<script>
   
    
    function add(){
        let  count=0
       return function (){
           app.innerHTML= count++ 
        }
    }
    let btn=document.querySelector('#btn')
    btn.addEventListener('click',add(),false)

   
     
    

    let f;
    function fn(){
      let num=Math.floor(Math.random()*10)+1  //1-10
      f=function(){
          return num
      }
    }
    fn()
    for(let i=0;i<3;i++){
        console.log(f());
    }

    //自调用
    ;(function fn(){
        let num=Math.floor(Math.random()*10)+1
        return function(){         
          for(let i=0;i<3;i++){
              console.log(num);
           }
        }
    })()()

    
</script>
</html>